<?php
/**
 * gpa_new Description
 * @package 
 * @name common
 * @filesource common.php
 * @author Meta Sanjaya
 */

 function __search_in($folder, $file, $return_all=false) {
     $folders = glob($folder . '*', GLOB_ONLYDIR);
     $files = glob($folder . '*.php');

     foreach($folders as $dir) {
         $files = array_merge($files, __search_in($dir . DIRECTORY_SEPARATOR, $file, true));
     }

     if($return_all) {
         return $files;
     }

     foreach($files as $f) {
         if(preg_match('|'.preg_quote($file).'|', $f)) {
             return $f;
         }
     }

     return false;
 }

 function __autoload($class) {
     try {
         include_once __search_in(__SYSTEM__, $class . '.php');
     } catch(Exception $e) {
         trigger_error($e->getTraceAsString());
     }
 }

 function pwd_gen() {
    $pwd="";
    $pwds = array();
    $args = func_get_args();

    for($i=0,$j=count($args);$i<$j;$i++) {
        $pwds[] = md5($args[$i].$i);
    }

    foreach($pwds as $p) {
        for($i=0,$j=32;$i<$j;$i++) {
            $pwd .= substr($p, $i, 1);
        }
    }
    
    return $pwd;
}


?>
